<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/12/29
 * Time: 9:38
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\web\middleware;

use think\facade\Session;

class Auth
{
    public function handle($request, \Closure $next)
    {
        $param = $request->param();
        $data = [
            'param'=>$param,
            "pathinfo"=>$request->pathinfo()
        ];
        $getUserOpenid = Session::get(config('key.session_key'));
        if(!$getUserOpenid) {
            if (!preg_match('/login/', $request->pathinfo())) {
                return redirect((string)url('login/auth', $data));
            }
        }
        $request->userOpenid = $getUserOpenid;
        return $next($request);
    }
}